
import { getweather, remindSwitch } from '../../utils/networkRequest.js' 
// pages/remind/remind.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    duration: 1500,
    tipsContent: '',
    $zanui: {
      toptips: {
        show: false
      }
    },
    cancelWithMask: true,
    actions: [{
      name: '关闭推送',
    }, {
      name: '开启推送',
    }],
    cancelText: '关闭',
    limit: null,// 限行信息
    oil: null,// 油价信息
    weather: null,// 天气信息

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let self = this;
    wx.getLocation({
      type: 'wgs84',
      success: function (res) {
        app.globalData.qqmapsdk && app.globalData.qqmapsdk.reverseGeocoder({
          location: {
            latitude: res.latitude,
            longitude: res.longitude
          },
          success: function (res) {
            let cityInfo = res.result.address_component
            getweather(cityInfo.city, cityInfo.province, (r) => { 
              if (r.code == 0) {
                self.setData({
                  limit: r.data.limit,
                  oil: r.data.oil,
                  weather: r.data.weather
                })
              }
            })
          },
          fail: function (res) {
            console.log(res);
          },
          complete: function (res) {
            console.log(res);
          }
        });



      }
    })



  },
  openActionSheet() {
    this.setData({
      'show': true
    });
  },
  closeActionSheet() {
    this.setData({
      'show': false
    });
  },

  handleActionClick({ detail }) {
    // 获取被点击的按钮 index
    const { index } = detail;

    remindSwitch("notify_travel", index, (r) => {
      if (r.code == 0) {
        this.closeActionSheet();

        this.setData({
          tipsContent: r.message,
          $zanui: {
            toptips: {
              show: true,
              
            }
          }
        });

        setTimeout(() => {
          this.setData({
            $zanui: {
              toptips: {
                show: false
              }
            }
          })
        }, 1500);


      } else {
        this.setData({
          tipsContent: r.message,
          $zanui: {
            toptips: {
              show: true,
              
            }
          }
        });

        setTimeout(() => {
          this.setData({
            $zanui: {
              toptips: {
                show: false
              }
            }
          })
        }, 1500);
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})